﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data.Models;

namespace Parafarmacia
{
    public partial class ProductosGestion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Update changes
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        protected void butActualizar_Click(object sender, EventArgs e)
        {
            ProductAdd();
        }

        /// <summary>
        /// Add product
        /// </summary>
        private void ProductAdd()
        {
            using (var db = new Data.Models.dbParafarmaciaContext())
            {
                tblProducto prod = new tblProducto();
                prod.NombreProducto = this.txtNombreProducto.Text;
                prod.Descripcion = this.txtDescripcion.Text;
                prod.Detalle = this.txtDetalle.Text;
                prod.Descuento = Convert.ToDecimal(this.txtDescuento.Text);
                prod.IdCategoria = Convert.ToInt16(txtCategoria.Text);
                prod.IdMarca = Convert.ToInt16(txtMarca.Text);
                prod.imageUrl = txtImagenUrl.Text;
                prod.Oferta = chckOferta.Checked;
                prod.Precio = Convert.ToDecimal(txtPrecio.Text);
                prod.Stock = Convert.ToInt16(txtStock.Text);
                prod.Tipo = txtTipo.Text;

                db.tblProductos.Add(prod);
                db.SaveChanges();

            }
        }
    }
}